/*
 * @file    bit_reverse.cpp
 * @author  edward <libo@tencent.com>
 * @date    2013-04-02
 * @brief   
 * */

#include <iostream>
using namespace std;

void reverse(int &x, int i, int j)
{
    int l = x >> i & 1;
    int r = x >> j & 1;
    if( l ^ r) {
        x ^= (1 << i) | (1 << j);
    }
}

int main() {
    int input = 3;
    int sz = sizeof(input) * 8;
    for(int i = 0; i < sz / 2; i++) {
        reverse(input, i, sz - i - 1); 
    }
    cout << input;
}
